import java.io.*;
import java.net.*;

public class ABCClient implements Runnable
{
	Socket socket;

	public ABCClient(Socket in) throws IOException
	{
		socket = in;
		Thread newThread = new Thread(this);
		newThread.start();
		go();
	}

	//Writes to the server
	public void go() throws IOException
	{
		//InputStreamReader isr;
		//OutputStreamWriter osr;
		Console C = System.console();
		OutputStream os = socket.getOutputStream();
		//BufferedOutputStream bos;
		//osr = new OutputStreamWriter(s.getOutputStream());
		//isr = new InputStreamReader(System.in);
		//BufferedReader F = new BufferedReader(isr);
		String in = "";
		int c;
		while(true)
		{
			in = new String(C.readPassword());
			os.write(10);
			os.flush();
			//in=F.readLine();

			//while( (c=isr.read()) != -1)
			//{
				//osr.write(c);
			//}
		}
	}

	//Reads from the server
	public void run()
	{
		try{
			InputStreamReader isr = new InputStreamReader(socket.getInputStream());
			int c;
			while( (c = isr.read()) != -1)
			{
				System.out.print( (char)c);
			}
		}
		catch(Exception e){}
	}

	public static void main(String[] args)
	{
		try{
			BufferedReader F = new BufferedReader(new InputStreamReader(System.in));
			Socket sock;

			String IP = "";
			System.out.print("Connect to IP at: ");
			IP = F.readLine(); //readLine() returns a string to turn a string in to an int use Integer.parseInt(*STRING*)

			int port = 6667;
			//System.out.print("Port: ");
			//port = Integer.parseInt(F.readLine());

			sock = new Socket();
			System.out.println("Connecting....");
			sock.connect(new InetSocketAddress(IP, port), 5000);

			String name = "";
			System.out.print("Name: ");
			name = F.readLine();

			OutputStreamWriter osw = new OutputStreamWriter(sock.getOutputStream());
			for(int x = 0; x < name.length(); x++)
				osw.write(name.charAt(x));
			osw.write(10);
			osw.flush();

			ABCClient client = new ABCClient(sock);
		}
		catch(Exception e){System.out.println(e);}
	}
}